
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    EMPLOYEE_NAME:'',//姓名
    EMPLOYEE_PASSWORD:'',//密码
    result:'',//注册的账号
    work:'',//工号
    Getphone:true,
  },


  // 61003681
// 888888



//登录接口
  login_a:function(){
          wx.request({
           url:app.globalData.interface+'/baoji/API_1103_EmployeeLogo', 
           method:'POST',
            data: {
              EMPLOYEE_NAME:this.data.EMPLOYEE_NAME,
              EMPLOYEE_PASSWORD:this.data.EMPLOYEE_PASSWORD,
              OPEN_ID: this.data.openid, //用户OPEN_ID
              session_key:this.data.session_key,
              OPEN_UUID:this.data.jiami
            },
            header:{
              'content-type':'application/x-www-form-urlencoded'
            },
            success:res=> {
              console.log(res)
              console.log(res.data.data.EMPLOYEE_ID)
              //员工工号
              let mealsList = res.data.data.EMPLOYEE_ID;
              app.globalData.mealsList = mealsList;

              let UUIDSTRING = res.data.data.UUIDSTRING;
              app.globalData.UUIDSTRING = UUIDSTRING;
              
              var gonghao = res.data.data.EMPLOYEE_ID
              this.setData({
                work:gonghao
              })
              console.log(this.data.work);

             res.data.result
              if( res.data.result == "error"){
                wx.showModal({
                  title: '温馨提示',
                  content: '请输入正确的账号或密码',
                  success: function (res) {
                    if (res.confirm) {//这里是点击了确定以后
                      console.log('用户点击确定')
                    } else {//这里是点击了取消以后
                      console.log('用户点击取消')
                    }
                  }
                })
              }else{//带工号跳转
                wx.navigateTo({
                  url: '../../pages/gxtiaoz/gxtiaoz?data='+this.data.work
                })
              }
            }
          })
    // }
    },

    word_shang(){
      wx.navigateTo({
        url: '../../pages/shangxiu/shangxiu'
      })
    },


    
    getPhoneNumber(e) {
      console.log(e);
      // console.log(e.detail.code)
      this.setData({
        code: e.detail.code
      })
      wx.request({ 
        url: app.globalData.interface+'/post/API_1032_getWeiXinPhone',
        method: 'GET',
        //向后端发送的数据
        data: {
          code: this.data.code  //将code发送到后台服务器。
        },  
        header: {
          "Content-Type": "application/x-www-form-urlencoded"  //POST方式是这个
        },
        success:res => { 
          console.log(res);
          console.log(res.data.phone);
          if (res.data.result != 'success') {
            wx.showToast({
              icon: 'error',
              title: '获取手机号失败',
              duration: 1000
            })
          } else {
            this.setData({
              phone:res.data.phone,
              Getphone: true,
            })
            this.baocunphone()//保存手机号接口
  
    
          }
        }
      })
    },
  
    baocunphone() {
      wx.request({ 
        url: app.globalData.interface+'/newVersion/API_2011_savePhoneAndOpenId',
        method: 'POST',
        //向后端发送的数据
        data: {
          CUSTOMER_TEL:this.data.phone,
     
          KEY:'xianjgjKey9999',
          OPEN_UUID: this.data.jiami,
          OPEN_ID:this.data.openid,
          session_key: this.data.session_key,
        },  
        header: {
          "Content-Type": "application/x-www-form-urlencoded"  //POST方式是这个
        },
        success:res => { 
          console.log(res);
        }
      })
  
    },
   

    onLoad:function (options) {
      this.setData({

        openid: app.globalData.openid,
  
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
      });
    },

    onShow() {
      setTimeout(() => {
        this.setData({
          phone: app.globalData.phone,
          openid: app.globalData.openid,
          jiami: app.globalData.jiami,
          OPEN_ID: app.globalData.openid,
          session_key: app.globalData.session_key,
        });
        console.log(this.data.phone);
        if (this.data.phone == '') {
    
          this.setData({
            Getphone:false,
          })
          
        }
      },1000)  
    },
  
})